package com.cat.dataStructure;

/**
*   @description 
*   @author 曲大人的喵 https://leetcode.cn/problems/132-pattern/
*   @create 2025/8/15 17:06
*   @since JDK17
*/

public class Solution18 {
    static int N = ((int) (2e5 + 10)), top;
    static int[] stack = new int[N];
    public boolean find132pattern(int[] nums) {
        int n = nums.length, k = Integer.MIN_VALUE;
        top = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (nums[i] < k) return true;
            // 来了一个更大的
            while (top > 0 && nums[stack[top - 1]] < nums[i]) {
                k = Math.max(k, nums[stack[--top]]);
            }
            stack[top++] = i;
        }
        return false;
    }
}
